package com.utonw.carloan.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Server on 2017/3/14.
 */

public class SharedPreferencesUtils {

    //Token字段
    private final static String TOKEN = "TOKEN";

    //获取Token
    public static String getToken(Context context) {
        SharedPreferences sp = context.getSharedPreferences(TOKEN, Context.MODE_PRIVATE);
        return sp.getString(TOKEN, "");
    }

    //退出时清空token
    public static void clearToken(Context context) {
        SharedPreferences sp = context.getSharedPreferences(TOKEN, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear().apply();
    }

    //保存token
    public static void saveToken(Context context, String token) {
        SharedPreferences sp = context.getSharedPreferences(TOKEN, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.clear();
        editor.putString(TOKEN, token);
        editor.apply();
    }

}
